<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
          
        */
        class NumArray {
            constructor (nums) {
                this.s = new Array(nums.length + 1)
                // 初始化第一个数是0
                this.s[0] = 0
                // 计算前缀和
                for (let i = 0; i < nums.length; i++) {
                    this.s[i + 1] = this.s[i] + nums[i]
                }
            }

            sumRange (left, right) {
                // 为right + 1减去left的值，如果第一个数不是0，那么用right - (left - 1)，会出现left - 1是小于0的情况，要判断
                return this.s[right + 1] - this.s[left]
            }
        }
    </script>
</body>

</html>